package com.example.inter.tourdemo.ui.fragment;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.listener.OnItemClickListener;
import com.example.inter.tourdemo.R;
import com.example.inter.tourdemo.adapter.TripAdapter;
import com.example.inter.tourdemo.ui.GlideImageLoader;
import com.example.inter.tourdemo.utils.MyApplication;
import com.youth.banner.Banner;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;
import me.yokeyword.fragmentation.SupportFragment;

import static com.example.inter.tourdemo.R.id.theme_rv_Boutique;

/**
 * 漫客传奇
 * Created by Inter巩海亮 on 2017-03-28.
 * 微信:
 * QQ号:
 * 邮箱:dahaizhiliang@126.com
 */

public class MKTravelsFragment extends SupportFragment {

    @Bind(R.id.banner)
    Banner mBanner;
    @Bind(R.id.rv_trip)
    RecyclerView mRvTrip;

    //banner本地资源文件
    Integer[] images = {R.drawable.trip_banner1, R.drawable.trip_banner2, R.drawable.trip_banner3};
    private ArrayList mTripDataList;
    private TripAdapter mTripAdapter;

    public static MKTravelsFragment newInstance() {

        Bundle args = new Bundle();
        MKTravelsFragment fragment = new MKTravelsFragment();
        fragment.setArguments(args);
        return fragment;
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View tripView = inflater.inflate(R.layout.fragment_travels, container, false);
        ButterKnife.bind(this, tripView);

        //测试 本地图片数据（资源文件）
        List list = new ArrayList();
        for (int i = 0; i < images.length; i++) {
            list.add(images[i]);
        }
        mBanner.setImages(list)
                .setImageLoader(new GlideImageLoader())
                .start();

        initData();
        return tripView;
    }

    public void initData() {
        mTripDataList = new ArrayList();

        for (int i = 0; i < 10; i++) {
            mTripDataList.add(i);
        }
        initAdapter();
    }

    private void initAdapter() {
        mTripAdapter = new TripAdapter(R.layout.trip_item,mTripDataList);

//        ★

        LinearLayoutManager layoutManager = new LinearLayoutManager(MyApplication.getContext());
        layoutManager.setSmoothScrollbarEnabled(true);
        layoutManager.setAutoMeasureEnabled(true);

        mRvTrip.setLayoutManager(layoutManager);
        mRvTrip.setHasFixedSize(true);
        mRvTrip.setNestedScrollingEnabled(false);


//        ★
//        LinearLayoutManager linearLayoutManagerTrip = new LinearLayoutManager(getContext());
//
//        mRvTrip.setLayoutManager(linearLayoutManagerTrip);
        mRvTrip.setAdapter(mTripAdapter);
        mRvTrip.addOnItemTouchListener(new OnItemClickListener() {
            @Override
            public void onSimpleItemClick(BaseQuickAdapter adapter, View view, int position) {
                Toast.makeText(getContext(),"点击了条目--" + position,Toast.LENGTH_SHORT).show();
            }
        });
    }


    @Override
    public void onDestroyView() {
        super.onDestroyView();
        ButterKnife.unbind(this);
    }
}


